package com.gaohe.scp.service.impl;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Random;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.gaohe.common.core.domain.entity.SysUser;
import com.gaohe.common.exception.ServiceException;
import com.gaohe.common.utils.DateUtils;
import com.gaohe.scp.domain.vo.CsCarDto;
import com.gaohe.scp.domain.vo.CsCarVo;
import com.gaohe.scp.domain.vo.CsNoticeVo;
import org.apache.ibatis.annotations.Param;
import com.gaohe.common.utils.StringUtils;
import com.gaohe.scp.domain.CsOrder;
import com.gaohe.scp.domain.*;
import com.gaohe.scp.domain.vo.CarAllInfoDTO;
import com.gaohe.scp.mapper.*;
import com.gaohe.system.mapper.SysUserMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import com.gaohe.scp.mapper.CsCarMapper;
import com.gaohe.scp.domain.CsCar;
import com.gaohe.scp.service.ICsCarService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 车辆管理Service业务层处理
 *
 * @author liuxiangyu
 * @date 2025-03-28
 */
@Service
public class CsCarServiceImpl implements ICsCarService {
    private static final Logger log = LoggerFactory.getLogger(CsCarServiceImpl.class);
    @Autowired
    private CsCarMapper csCarMapper;
    @Autowired
    private CsCarSituationMapper situationMapper;
    @Autowired
    private CsCarParameterMapper parameterMapper;
    @Autowired
    private CsCarBelongMapper belongMapper;
    @Autowired
    private CsCarQuoteMapper csCarQuoteMapper;
    @Autowired
    private CsCarAssessMapper csCarAssessMapper;
    @Autowired
    private CsCarExplainMapper csCarExplainMapper;
    @Autowired
    private CsCarParameterMapper csCarParameterMapper;
    @Autowired
    private CsCarSituationMapper csCarSituationMapper;
    @Autowired
    private CsCarBelongMapper csCarBelongMapper;
    @Autowired
    private CsCarVisitMapper csCarVisitMapper;
    @Autowired
    private SysUserMapper sysUserMapper;
    @Autowired
    private CsOrderMapper csOrderMapper;
    @Autowired
    private CsOrderDetailMapper csOrderDetailMapper;

    /**
     * 作者:张文豪
     * json格式校验
     *
     * @param json
     * @return
     */
    // 校验JSON合法性的工具方法
    private boolean isValidJson(String json) {
        try {
            new ObjectMapper().readTree(json);
            return true;
        } catch (IOException e) {
            return false;
        }
    }


    /**
     * 查询车辆管理
     *
     * @param carId 车辆管理主键
     * @return 车辆管理
     */
    @Override
    public CsCar selectCsCarByCarId(Long carId) {
        return csCarMapper.selectCsCarByCarId(carId);
    }

    /**
     * 查询车辆管理列表
     *
     * @param csCar 车辆管理
     * @return 车辆管理
     */
    @Override
    public List<CsCar> selectCsCarList(CsCar csCar) {
        return csCarMapper.selectCsCarList(csCar);
    }

    /**
     * 查询车辆管理列表
     *
     * @param csCar 车辆管理
     * @return 车辆管理
     */
    @Override
    public List<CsCar> GldSelectCsCarList(CsCar csCar) {
        csCar.setDelFlag("0");
        return csCarMapper.selectCsCarList(csCar);
    }

    /**
     * 新增车辆管理
     *
     * @param csCar 车辆管理
     * @return 结果
     */
    @Override
    public int insertCsCar(CsCar csCar) {
        csCar.setCreateTime(DateUtils.getNowDate());
        return csCarMapper.insertCsCar(csCar);
    }

    /**
     * 修改车辆管理
     *
     * @param csCar 车辆管理
     * @return 结果
     */
    @Override
    public int updateCsCar(CsCar csCar) {
        csCar.setUpdateTime(DateUtils.getNowDate());
        return csCarMapper.updateCsCar(csCar);
    }


    /**
     * 删除车辆管理信息
     *
     * @param carId 车辆管理主键
     * @return 结果
     */
    @Override
    public int deleteCsCarByCarId(Long carId) {
        return csCarMapper.deleteCsCarByCarId(carId);
    }


    /**
     * 作者:张文豪
     * 修改多表
     *
     * @param dto
     * @return
     */
    @Override
    @Transactional
    public int updateAllCarInfo(CarAllInfoDTO dto) {
        log.info("updateDto:{}", dto);
        Long carId = dto.getCarId();
//        设置更新时间段
        dto.setUpdateTime(new Date());
//        1.更新主表cs_car
        CsCar csCar = new CsCar();
        BeanUtils.copyProperties(dto, csCar);
        csCarMapper.updateCsCar(csCar);

//        2.更新cs_car_situation表
        CsCarSituation csCarSituation = new CsCarSituation();
        BeanUtils.copyProperties(dto, csCarSituation);
        csCarSituationMapper.updateAllCarInfo(csCarSituation);

//        3.更新cs_car_parameter表
        CsCarParameter csCarParameter = new CsCarParameter();
        BeanUtils.copyProperties(dto, csCarParameter);
        csCarParameter.setParameter(dto.getParameterJson());
        csCarParameterMapper.updateAllCarInfo(csCarParameter);

//        4.更新cs_car_belong表
        CsCarBelong csCarBelong = new CsCarBelong();
        BeanUtils.copyProperties(dto, csCarBelong);
        csCarBelongMapper.updateAllCarInfo(csCarBelong);

//        5.更新cs_quote表
        CsCarQuote csCarQuote = new CsCarQuote();
        BeanUtils.copyProperties(dto, csCarQuote,"price");
        csCarQuoteMapper.updateAllCarInfo(csCarQuote);
        BigDecimal maxPrice = csCarQuoteMapper.selectCsCarQuoteByCarId(carId).getPrice();

//        6.更新cs_car_assess表
        //先删除，再新增
        //删除所有该car表的评估记录
        csCarAssessMapper.deleteCsCarAssessByCarId(carId);
        List<CsCarAssess> assessList = dto.getAssessmentData();
        if (CollectionUtils.isNotEmpty(assessList)) {
            // 设置每个评估数据的carId和carName
            final String carName = dto.getCarName();
            for (CsCarAssess item : assessList) {
                item.setCarId(carId);
                item.setDelFlag("0");
                item.setCarName(carName);
                item.setCreateTime(DateUtils.getNowDate());
                item.setUpdateTime(DateUtils.getNowDate());

                csCarAssessMapper.insertCsCarAssess(item);
            }
        }
//        for (CsCarAssess item : assessList) {
//
//            BeanUtils.copyProperties(dto, item);
//            if (item.getDelFlag() == null) {
//                item.setDelFlag("0");
//            }
//            item.setUpdateTime(new Date());
//            csCarAssessMapper.insertCsCarAssess(item);
//        }

        //7.更新cs_car_explain表
        CsCarExplain csCarExplain = new CsCarExplain();
        BeanUtils.copyProperties(dto, csCarExplain);
        csCarExplainMapper.updateAllCarInfo(csCarExplain);

        //8.cs_order表新增 如果状态为待成交或完成成交
        //待成交
        if (Objects.equals(dto.getStatus(), "待成交")) {
            //先查询订单表
            List<CsOrder> csOrderList = csOrderMapper.selectCsOrderByCarId(carId);
            if (csOrderList.size() == 0) {
                //新增订单
                CsOrder csOrder = new CsOrder();
                csOrder.setCarId(dto.getCarId());
                csOrder.setUserId(dto.getUserId());
                SysUser sysUser = sysUserMapper.selectUserById(dto.getUserId());
                csOrder.setUserName(sysUser.getUserName());
                csOrder.setWay("线上支付");
                csOrder.setType("待付款");
                //查询订单价格
                csOrder.setPrice(maxPrice);
                //生成订单编号
                csOrder.setOrderNo(getRandom());
                csOrder.setAddress(dto.getBelongAddress());
                csOrder.setCreateTime(new Date());
                csOrder.setDelFlag("0");
                csOrderMapper.insertCsOrder(csOrder);

                //9.cs_order_detail表新增
                CsOrderDetail csOrderDetail = new CsOrderDetail();
                csOrderDetail.setOrderId(csOrder.getOrderId());
                csOrderDetail.setCarId(dto.getCarId());
                csOrderDetail.setCarName(dto.getCarName());
                csOrderDetail.setStartPrice(String.valueOf(dto.getStartPrice()));
                csOrderDetail.setAddPrice(String.valueOf(dto.getAddPrice()));
                csOrderDetail.setStartTime(dto.getStartTime());
                csOrderDetail.setEndTime(dto.getEndTime());
                csOrderDetail.setCreateTime(dto.getCreateTime());
                csOrderDetail.setDelFlag("0");
                csOrderDetailMapper.insertCsOrderDetail(csOrderDetail);
            }else {
                //修改订单
                CsOrder csOrder1 = csOrderList.get(0);
//                CsOrder csOrder = new CsOrder();
                csOrder1.setCarId(dto.getCarId());
                csOrder1.setUserId(dto.getUserId());
                SysUser sysUser = sysUserMapper.selectUserById(dto.getUserId());
                csOrder1.setUserName(sysUser.getUserName());
                csOrder1.setWay("线上支付");
                csOrder1.setType("待付款");
                csOrder1.setAddress(dto.getBelongAddress());
                csOrder1.setCreateTime(new Date());
                csOrder1.setDelFlag("0");
                csOrderMapper.updateCsOrder(csOrder1);
            }
        }
        //完成成交
        if (Objects.equals(dto.getStatus(), "完成成交")) {
            //先查询订单表
            List<CsOrder> csOrderList = csOrderMapper.selectCsOrderByCarId(carId);
            if (csOrderList.size() == 0) {
                //新增订单
                CsOrder csOrder = new CsOrder();
                csOrder.setCarId(dto.getCarId());
                csOrder.setUserId(dto.getUserId());
                SysUser sysUser = sysUserMapper.selectUserById(dto.getUserId());
                csOrder.setUserName(sysUser.getUserName());
                csOrder.setWay("线上支付");
                csOrder.setType("已付款");
                csOrder.setAddress(dto.getBelongAddress());
                csOrder.setCreateTime(new Date());
                csOrder.setDelFlag("0");
                //查询订单价格
                csOrder.setPrice(maxPrice);
                //生成订单编号
                csOrder.setOrderNo(getRandom());
                csOrderMapper.insertCsOrder(csOrder);

                //9.cs_order_detail表新增
                CsOrderDetail csOrderDetail = new CsOrderDetail();
                csOrderDetail.setOrderId(csOrder.getOrderId());
                csOrderDetail.setCarId(dto.getCarId());
                csOrderDetail.setCarName(dto.getCarName());
                csOrderDetail.setStartPrice(String.valueOf(dto.getStartPrice()));
                csOrderDetail.setAddPrice(String.valueOf(dto.getAddPrice()));
                csOrderDetail.setStartTime(dto.getStartTime());
                csOrderDetail.setEndTime(dto.getEndTime());
                csOrderDetail.setCreateTime(dto.getCreateTime());
                csOrderDetail.setDelFlag("0");
                csOrderDetailMapper.insertCsOrderDetail(csOrderDetail);
            }else {
                //修改订单
                CsOrder csOrder1 = csOrderList.get(0);
//                CsOrder csOrder = new CsOrder();
                csOrder1.setCarId(dto.getCarId());
                csOrder1.setUserId(dto.getUserId());
                SysUser sysUser = sysUserMapper.selectUserById(dto.getUserId());
                csOrder1.setUserName(sysUser.getUserName());
                csOrder1.setWay("线上支付");
                csOrder1.setType("已付款");
                csOrder1.setAddress(dto.getBelongAddress());
                csOrder1.setCreateTime(new Date());
                csOrder1.setDelFlag("0");
                csOrderMapper.updateCsOrder(csOrder1);
            }

        }


        return 1;
    }

    @Override
    public int deleteCsCarByCarIds(Long[] carIds) {
        return 0;
    }


    /**
     * 作者:张文豪
     * 新增多表
     *
     * @param dto
     * @return
     */
    @Transactional
    public int insertAllCarInfo(CarAllInfoDTO dto) {
        SysUser user = sysUserMapper.selectUserByUserName(dto.getBelongPerson());

        log.info("dto:{}", dto);
        // 设置基础时间字段
        dto.setCreateTime(DateUtils.getNowDate());
        dto.setUpdateTime(DateUtils.getNowDate());
//        delFlag新增赋0
        dto.setDelFlag("0");

        // 1. 插入主表 cs_car
        CsCar car = new CsCar();
        BeanUtils.copyProperties(dto, car);
        car.setStatus("未开始");
        csCarMapper.insertCsCar(car);

        // 获取主键 - 一次性确定，确保是effectively final
        final Long carId;
        if (car.getCarId() != null) {
            carId = car.getCarId();
        } else {
            Long tempId = csCarMapper.selectLastInsertId();
            if (tempId == null) {
                throw new ServiceException("获取主键失败");
            }
            carId = tempId;
            car.setCarId(carId);
        }

        // 将确定的carId设置到DTO
        dto.setCarId(carId);

        // 2. 插入车况表 cs_car_situation
        CsCarSituation situation = new CsCarSituation();
        BeanUtils.copyProperties(dto, situation);
        situationMapper.insertCsCarSituation(situation);

        // 3. 插入参数表 cs_car_parameter
        if (!isValidJson(dto.getParameterJson())) {
            throw new ServiceException("参数JSON格式错误");
        }
        CsCarParameter parameter = new CsCarParameter();
        parameter.setCarId(carId);
        parameter.setCarName(dto.getCarName());
//        System.err.println(dto.getParameterJson());
//        System.err.println(111);
        String parameterJson = dto.getParameterJson();
        if (!Objects.equals(parameterJson, "") && parameterJson != null){
            parameter.setParameter(dto.getParameterJson());
        }

        parameter.setImages(dto.getImages());
        parameter.setDelFlag("0");
        parameterMapper.insertCsCarParameter(parameter);

        // 4. 插入归属表 cs_car_belong
        CsCarBelong belong = new CsCarBelong();
        belong.setCarId(carId);
        belong.setCarName(dto.getCarName());
        BeanUtils.copyProperties(dto, belong);
        belong.setBelongAddress(dto.getBelongAddress());
        belongMapper.insertCsCarBelong(belong);

        // 5. 插入报价表 cs_car_quote
        CsCarQuote csCarQuote = new CsCarQuote();
        BeanUtils.copyProperties(dto, csCarQuote);
        csCarQuote.setPrice(BigDecimal.ZERO);
        csCarQuoteMapper.insertCsCarQuote(csCarQuote);

        // 6. 插入车辆评估检测表
        List<CsCarAssess> assessList = dto.getAssessmentData();  // 直接获取List，不需要字符串处理

        if (CollectionUtils.isNotEmpty(assessList)) {
            // 设置每个评估数据的carId和carName
            final String carName = dto.getCarName();
            for (CsCarAssess item : assessList) {
                item.setCarId(carId);
                item.setDelFlag("0");
                item.setCarName(carName);

                if (item.getCreateTime() == null) {
                    item.setCreateTime(DateUtils.getNowDate());
                    item.setUpdateTime(new Date());
                }
                csCarAssessMapper.insertCsCarAssess(item);
            }

            // 批量插入
//            csCarAssessMapper.batchInsertAssess(assessList);
        }

        // 7. 插入车辆成交说明表
        CsCarExplain csCarExplain = new CsCarExplain();
        BeanUtils.copyProperties(dto, csCarExplain);
        csCarExplainMapper.insertCsCarExplain(csCarExplain);

        //8.cs_car-visit表新增
        CsCarVisit csCarVisit = new CsCarVisit();
        csCarVisit.setCarId(carId);
        csCarVisit.setCarName(dto.getCarName());
        csCarVisit.setView((long) 0);
        csCarVisit.setCollect((long) 0);
        csCarVisit.setDelFlag("0");
        csCarVisit.setCreateTime(new Date());
        csCarVisit.setUpdateTime(new Date());
        csCarVisitMapper.insertCsCarVisit(csCarVisit);
        return 1;
    }

    @Override
    public int deleteAllCarInfo(Long carId) {
        return 0;
    }

    /**
     * 作者:张文豪
     *
     * @param carId 查询多表
     *  TODO 用户id查询不到
     * @return
     */
    @Transactional
    @Override
    public CarAllInfoDTO selectCarAllInfoDto(Long carId) {
        CarAllInfoDTO carAllInfoDTO = new CarAllInfoDTO();

        // 查询数据并记录日志
        CsCar csCar = csCarMapper.selectCsCarByCarId(carId);
        log.info("csCar:{}", csCar);
        List<CsCarAssess> csCarAssess = csCarAssessMapper.selectCsCarAssessByCarId(carId);
        log.info("csCarAssess:{}", csCarAssess);
        CsCarQuote csCarQuote = csCarQuoteMapper.selectCsCarQuoteByCarId(carId);
        log.info("csCarQuote:{}", csCarQuote);
        CsCarExplain csCarExplain = csCarExplainMapper.selectCsCarExplainByCarId(carId);
        log.info("csCarExplain:{}", csCarExplain);
        CsCarParameter csCarParameter = csCarParameterMapper.selectCsCarParameterByCarId(carId);
        log.info("csCarParameter:{}", csCarParameter);
        CsCarSituation csCarSituation = csCarSituationMapper.selectCsCarSituationByCarId(carId);
        log.info("csCarSituation:{}", csCarSituation);
        CsCarBelong csCarBelong = csCarBelongMapper.selectCsCarBelongByCarId(carId);
        log.info("csCarBelong:{}", csCarBelong);

        // 1.从cs_car表获取数据 - 添加空值检查
        if (csCar != null) {
            carAllInfoDTO.setCarId(csCar.getCarId());
            carAllInfoDTO.setCarName(csCar.getCarName());
            carAllInfoDTO.setIsPush(csCar.getIsPush());
            carAllInfoDTO.setImage(csCar.getImage());
            carAllInfoDTO.setStartPrice(csCar.getStartPrice());
            carAllInfoDTO.setAddPrice(csCar.getAddPrice());
            carAllInfoDTO.setAddress(csCar.getAddress());
            carAllInfoDTO.setCreateTime(csCar.getCreateTime());
            carAllInfoDTO.setUpdateTime(csCar.getUpdateTime());
            carAllInfoDTO.setDelFlag(csCar.getDelFlag());
            carAllInfoDTO.setStartTime(csCar.getStartTime());
            carAllInfoDTO.setEndTime(csCar.getEndTime());
            carAllInfoDTO.setIsPush(csCar.getIsPush());
            carAllInfoDTO.setStatus(csCar.getStatus());
            if (csCar.getUserId() != null){
                carAllInfoDTO.setUserId(csCar.getUserId());
            }
        }

        // 2.从cs_car_assess表中获取数据
        // 目前没有从此表获取数据的代码
        if (csCarAssess != null) {
            carAllInfoDTO.setAssessmentData(csCarAssess);
        }

        // 3.从cs_car_belong表中获取数据 - 添加空值检查
        if (csCarBelong != null) {
            carAllInfoDTO.setBelongPerson(csCarBelong.getBelongPerson());
            carAllInfoDTO.setBelongAddress(csCarBelong.getBelongAddress());
            carAllInfoDTO.setSex(csCarBelong.getSex());
            carAllInfoDTO.setPhone(csCarBelong.getPhone());
            carAllInfoDTO.setBirthday(csCarBelong.getBirthday());
            carAllInfoDTO.setIdNumber(csCarBelong.getIdNumber());
            carAllInfoDTO.setEmail(csCarBelong.getEmail());
        }

        // 4.从cs_car_explain表中获取数据 - 这里是问题所在，添加空值检查
        if (csCarExplain != null) {
            carAllInfoDTO.setExplainContent(csCarExplain.getExplainContent());
        } else {
            log.warn("CsCarExplain is null for carId: {}", carId);
            // 可以设置一个默认值或者留空
            // carAllInfoDTO.setExplainContent("");
        }

        // 5.从cs_car_parameter表中获取数据 - 添加空值检查
        if (csCarParameter != null) {
            carAllInfoDTO.setParameterJson(csCarParameter.getParameter());
            carAllInfoDTO.setImages(csCarParameter.getImages());
        }

        // 6.从cs_car_quote表中获取数据 - 添加空值检查
        if (csCarQuote != null) {
            carAllInfoDTO.setPrice(csCarQuote.getPrice());
            carAllInfoDTO.setType(csCarQuote.getType());
        }

        // 7.从cs_car_situation表中获取数据 - 添加空值检查
        if (csCarSituation != null) {
            carAllInfoDTO.setContent(csCarSituation.getContent());
            carAllInfoDTO.setPaifangStand(csCarSituation.getPaifangStand());
            carAllInfoDTO.setColor(csCarSituation.getColor());
            carAllInfoDTO.setNovel(csCarSituation.getNovel());
            carAllInfoDTO.setGearbox(csCarSituation.getGearbox());
            carAllInfoDTO.setPowerType(csCarSituation.getPowerType());
            carAllInfoDTO.setPower(csCarSituation.getPower());
        }

        log.info("dto:{}", carAllInfoDTO);
        return carAllInfoDTO;
    }

    /**
     * 作者:张文豪
     * 逻辑删除
     *
     * @param carId
     * @return
     */
    @Override
    public int delAllCarInfo(Long carId) {
//        1.cs_car表更新flag
        CsCar csCar = new CsCar();
        csCar.setCarId(carId);
        csCar.setDelFlag("2");
        csCarMapper.updateCsCar(csCar);

//        2.cs_car_parameter表更新
        CsCarParameter csCarParameter = new CsCarParameter();
        csCarParameter.setCarId(carId);
        csCarParameter.setDelFlag("2");
        csCarParameterMapper.updateAllCarInfo(csCarParameter);

//        3.cs_car_quote更新
        CsCarQuote csCarQuote = new CsCarQuote();
        csCarQuote.setCarId(carId);
        csCarQuote.setDelFlag("2");
        csCarQuoteMapper.updateAllCarInfo(csCarQuote);

//        4.cs_car_assess更新
        CsCarAssess csCarAssess = new CsCarAssess();
        csCarAssess.setCarId(carId);
        csCarAssess.setDelFlag("2");
        csCarAssessMapper.updateAllCarInfo(csCarAssess);

//         5.cs_car_belong更新
        CsCarBelong csCarBelong = new CsCarBelong();
        csCarBelong.setCarId(carId);
        csCarBelong.setDelFlag("2");
        csCarBelongMapper.updateAllCarInfo(csCarBelong);

//        6.cs_car_situation更新
        CsCarSituation csCarSituation = new CsCarSituation();
        csCarSituation.setCarId(carId);
        csCarSituation.setDelFlag("2");
        csCarSituationMapper.updateAllCarInfo(csCarSituation);

//        7.cs_car_explain更新
        CsCarExplain csCarExplain = new CsCarExplain();
        csCarExplain.setCarId(carId);
        csCarExplain.setDelFlag("2");
        csCarExplainMapper.updateAllCarInfo(csCarExplain);


        return 1;
    }

    //往期竞拍和在售车辆
    @Override
    public List<CsCarVo> selectWangqiAndMaiIng(CsCar csCar) {
        List<CsCarVo> csCarVos = csCarMapper.selectWangqiAndMaiIng(csCar);
        return csCarVos;
    }

    //我的关注
    @Override
    public List<CsCarVo> selectMyGuanZhu(Long userId) {
        List<CsCarVo> csCarVos = csCarMapper.selectMyGuanZhu(userId);
        System.err.println(csCarVos);
        return csCarVos;
    }

    //今日竞拍
    @Override
    public List<CsCarVo> todayJingPai(CsCar csCar) {
        Date nowDate = DateUtils.getNowDate();
        System.err.println(nowDate);
        List<CsCarVo> csCarVos = csCarMapper.todayJingPai(csCar);
        return csCarVos;
    }

    //搜索车辆
    @Override
    public List<CsCarVo> searchCar(CsCar csCar) {
        List<CsCarVo> csCarVos = csCarMapper.searchCar(csCar);
        return csCarVos;
    }

    @Override
    public List<CsCarVo> allCar(CsCarDto csCarDto) {
        System.err.println(csCarDto);
        String order = csCarDto.getOrder();


        if (Objects.equals(order, "价格正序")) {
            return csCarMapper.allCarAscSearch(csCarDto);
        }
        if (Objects.equals(order, "价格倒序")) {
            return csCarMapper.allCarDescSearch(csCarDto);
        }

        return csCarMapper.allCar(csCarDto);
    }

    //我的预约
    @Override
    public List<CsCarVo> myReserve(CsCar csCar) {

        List<CsCarVo> csCarVos = csCarMapper.myReserve(csCar);
        System.err.println(csCarVos);
        return csCarVos;
    }

    @Override
    public int updateReserverDetail(Long carId) {
        return csCarMapper.updateReserverDetail(carId);
    }

    @Override
    public CsCar selectReserverStatus(Long carId) {
        return csCarMapper.selectReserverStatus(carId);
    }

    @Override
    public List<CsCar> selectCsCarListStatus() {
        return csCarMapper.selectCsCarListStatus();
    }

    String getRandom(){

        Random random = new Random();
        StringBuilder result= new StringBuilder();
        for (int i=0;i<6;i++)
        {
            result.append(random.nextInt(10));
        }
        return result.toString();
    }

}
